package com.zmn.plat.services.impl.product.tariff.item;

import java.util.List;

import javax.annotation.Resource;

import com.zmn.plat.common.dto.price.ItemTo;
import com.zmn.plat.model.entity.product.tariff.ProductTariff;
import com.zmn.plat.model.entity.product.tariff.item.ProductItemQuery;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import com.zmn.plat.model.entity.product.tariff.item.ProductTariffGroupItem;
import com.zmn.plat.model.entity.product.tariff.item.ProductTariffGroupItemQuery;
import com.zmn.plat.model.vo.product.tariff.item.ProductTariffGroupItemStatusVo;
import com.zmn.plat.model.vo.product.tariff.item.ProductTariffGroupItemVo;
import com.zmn.plat.persistence.interfaces.product.tariff.item.ProductTariffGroupItemDao;
import com.zmn.plat.services.interfaces.product.tariff.item.ProductTariffGroupItemService;

@Service
public class ProductTariffGroupItemServiceImpl implements ProductTariffGroupItemService {

    @Resource
    ProductTariffGroupItemDao productFaultItemDao;

    @Override
    public ProductTariffGroupItem findByKey(Integer relateId) {
        return productFaultItemDao.findByKey(relateId);
    }

    @Override
    public List<ProductTariffGroupItem> listPageByQuery(ProductTariffGroupItemQuery query) {
        int count = countByQuery(query);
        query.setTotalCount(count);
        return productFaultItemDao.listPageByQuery(query);
    }

    @Override
    public List<ProductTariffGroupItemVo> listByQuery(ProductTariffGroupItemQuery query) {
        return productFaultItemDao.listByQuery(query);
    }

    @Override
    public List<ProductTariffGroupItemVo> listByGroupId(Integer groupId, Integer tariffId) {
        return productFaultItemDao.listByGroupId(groupId, tariffId);
    }

    @Override
    public List<ProductTariffGroupItemVo> listItemByQuery(ProductTariffGroupItemQuery query) {
        return productFaultItemDao.listItemByQuery(query);
    }

    @Override
    public List<ProductTariffGroupItem> listAll() {
        return productFaultItemDao.listAll();
    }

    @Override
    @Cacheable(cacheNames = "redis1d", key = "'price:listSpecialItemByIdList:itemIdList:'+#p0", unless = "#result == null")
    public List<ProductTariffGroupItemVo> listSpecialItemByIdList(List<Integer> itemIdList) {
        return productFaultItemDao.listSpecialItemByIdList(itemIdList);
    }

    @Override
    public List<ProductTariffGroupItem> listByGroupIds(List<Integer> faultGroupIds) {
        return productFaultItemDao.listByGroupIds(faultGroupIds);
    }

    @Override
    public List<ProductTariffGroupItemVo> listByTariffIdAndCityIdAndProductId(Integer tariffId, Integer cityId, Integer productId) {
        return productFaultItemDao.listByTariffIdAndCityIdAndProductId(tariffId, cityId, productId);
    }

    @Override
    public List<ProductTariffGroupItemStatusVo> listProductTariffStatusByProductIdAndShowType(Integer productId, Integer showType) {
        return productFaultItemDao.listProductTariffStatusByProductIdAndShowType(productId, showType);
    }

    @Override
    @Cacheable(cacheNames = "redis10m", key = "'price:countByQuery:ProductTariffGroupItemQuery:'+#p0", unless = "#result == null")
    public Integer countByQuery(ProductTariffGroupItemQuery query) {
        return productFaultItemDao.countByQuery(query);
    }

    @Override
    public Integer updateSortByKey(ProductTariffGroupItem productFaultItem) {
        return productFaultItemDao.updateSortByKey(productFaultItem);
    }

    @Override
    public Integer updateSortByKey(Integer relateId, Integer sort, String mcStaffName) {
        ProductTariffGroupItem productFaultItem = new ProductTariffGroupItem();
        productFaultItem.setRelateId(relateId);
        productFaultItem.setSort(sort);
        productFaultItem.setUpdater(mcStaffName);

        return updateSortByKey(productFaultItem);
    }

    @Override
    public Integer updateByKey(ProductTariffGroupItem productFaultItem) {
        return productFaultItemDao.updateByKey(productFaultItem);
    }

    @Override
    public Integer insert(ProductTariffGroupItem productFaultItem) {
        return productFaultItemDao.insert(productFaultItem);
    }

    @Override
    public Integer insertBatch(List<ProductTariffGroupItem> productFaultItemList) {
        return productFaultItemDao.insertBatch(productFaultItemList);
    }

    @Override
    public Integer deleteByKey(Integer relateId) {
        return productFaultItemDao.deleteByKey(relateId);
    }

    @Override
    public Integer deleteByProductIdAndTariffId(Integer productId, Integer tariffId) {
        return productFaultItemDao.deleteByProductIdAndTariffId(productId, tariffId);
    }

    @Override
    public Integer deleteByProductIdAndTariffIdAndGroupIds(Integer productId, Integer tariffId, List<Integer> groupIds) {
        return productFaultItemDao.deleteByProductIdAndTariffIdAndGroupIds(productId, tariffId, groupIds);
    }

    @Override
    public Integer deleteByItemId(Integer itemId) {
        return productFaultItemDao.deleteByItemId(itemId);
    }

    @Override
    public Integer deleteByGroupIds(List<Integer> groupIds) {
        return productFaultItemDao.deleteByGroupIds(groupIds);
    }



    /********************************* 重构时直接使用 ************************************************/

    @Override
    @Cacheable(cacheNames = "redis10m", key = "'price:ratio:listItemPriceByQuery:ProductItemQuery:'+#p0", unless = "#result == null")
    public List<ItemTo> listItemPriceByQuery(ProductItemQuery query) {
        return productFaultItemDao.listItemPriceByQuery(query);
    }
}